import { RuntimeOptionsConfig } from '@alilc/lowcode-types';
import { RequestOptions, } from 'universal-request/lib/types';
import { AxiosInstance } from 'axios';
import { getAxiosInstance } from './common/axios/httpInstance';

export function createAxiosHandler(config?: Record<string, unknown>) {
  return async function(options: RuntimeOptionsConfig) {
    console.log('options', clearImmediate)
    const requestConfig: RequestOptions = {
      ...options,
      url: options.uri,
      method: options.method as RequestOptions['method'],
      data: options.params,
      headers: options.headers,
      ...config,
    };
    // console.log('Config', config.get('env2', true))
    const axiosInstance: AxiosInstance = getAxiosInstance(options?.params?.module);
    const response = await axiosInstance(requestConfig);
    console.log('responseData', response)
    return response;
  };
}